#include <bits/stdc++.h>
using namespace std;
int t;
int vis[100005];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>t;
	for(int i=1;i<=t;i++){
		int n,m,l,V,p[100005],d[100005],v[100005],a[100005];
		cin>>n>>m>>l>>V;
		memset(vis,0,sizeof(vis));
		for(int j=1;j<=n;j++){
			cin>>d[j]>>v[j]>>a[j];
		}
		for(int k=1;k<=m;k++){
			cin>>p[k];
		}
		for(int j=1;j<=n;j++){
			if(a[j]==0 && v[j]<V){
				break;
			}else if(a[j]==0 && v[j]>V){
				for(int g=1;g<=m;g++){
					vis[p[g]]=1;
				}
		    }else{
				for(int k=d[j];k<=l;k++){
					if(sqrt(v[j]+2*a[j]*(k-d[j]))>V){
						if(a[j]>0){
							for(int y=1;y<=m;y++){
								if(p[y]>=k){
									vis[p[y]]=1;
								}
							}
							break;
						}else{
							for(int y=1;y<=m;y++){
								if(p[y]>=k){
									vis[p[y]]=1;
									break;
								}
							}
							break;
						}
					}
				}
			}
		}
	}
	if(t==1){
		cout<<"3"<<" "<<"3";
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
